package com.neuedu.autosale.sys.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.autosale.entity.Pager;
import com.neuedu.autosale.entity.Result;
import com.neuedu.autosale.sys.entity.OutStorage;
import com.neuedu.autosale.sys.service.OutStorageService;

@Controller
public class OutStorageController {
	@Autowired
	private OutStorageService outStorageService;

	@RequestMapping("outstorage/index")
	public String outStorageIndex() {
		return "storage/outstoragelist";
	}

	@RequestMapping("outstorage/list")
	@ResponseBody
	public Pager<OutStorage> outStorageList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		Pager<OutStorage> pager = new Pager<>(page, rows);
		List<OutStorage> outStorageList = outStorageService.findListByPager(pager);
		int total = outStorageService.findTotalByPager(pager);
		pager.setRows(outStorageList);
		pager.setTotal(total);
		return pager;
	}

	@RequestMapping("outstorage/add")
	@ResponseBody
	public Result doAdd(OutStorage outStorage) {
		Result result = outStorageService.add(outStorage);
		return result;
	}

	@RequestMapping("outstorage/edit")
	@ResponseBody
	public Result doEdit(OutStorage outStorage) {
		Result result = outStorageService.edit(outStorage);
		return result;
	}

	@RequestMapping("outstorage/delete")
	@ResponseBody
	public Result doAdd(Integer outStoId) {
		List<OutStorage> list = new ArrayList<OutStorage>();
		list.add(new OutStorage(outStoId));
		Result result = outStorageService.deleteByIds(list);
		return result;
	}

}
